package com.lagou.edu.factory;

import com.lagou.edu.annotation.handler.AnnoHandler;
import com.lagou.edu.service.TransferService;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class AnnotationBeanFactory {

    private static Map<String, Object> map = new HashMap<>();

    static {
        try {
            AnnoHandler.component("com.lagou.edu", map);
        } catch (Exception e) {
            System.err.println("出现异常");
        }

        Collection<Object> values = map.values();
        map.forEach((x, y) -> {
            AnnoHandler.autowired(y, map);
        });
        map.forEach((x, y) -> {
            AnnoHandler.transactional(y, map);
        });
    }

    // 任务二：对外提供获取实例对象的接口（根据id获取）
    public static Object getBean(String name) {
        return map.get(name);
    }
}
